﻿<UserControl x:Class="RZD_maps.Modules.Transport.Views.View"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:RZD_maps.Modules.Transport"
             xmlns:vm="clr-namespace:RZD_maps.Modules.Transport.Models"
             xmlns:cm="clr-namespace:System.ComponentModel;assembly=WindowsBase">
    <UserControl.Resources>

        <vm:Model x:Key="Station" />

        <!-- a data template for bound ShopCategory instances -->
        <DataTemplate x:Key="CategoryTemplate"
                DataType="{x:Type vm:TransportCategory}">
            <StackPanel x:Name="GroupPanel"
                Orientation="Horizontal"
                Margin="0,2,0,2">
                <Image x:Name="Folder"
             Source="Images/FolderClosed.png" />
                <TextBlock x:Name="CategoryName"
                 Margin="2,0,0,0"
                 Text="{Binding Path=CategoryName}" />
            </StackPanel>

            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                   Value="True">
                    <Setter Property="Source"
                TargetName="Folder"
                Value="Images/FolderOpen.png" />
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}}"
                   Value="True">
                    <Setter Property="Foreground"
                TargetName="CategoryName"
                Value="Blue" />
                    <!--"White"-->
                    <Setter Property="Source"
                TargetName="Folder"
                Value="Images/FolderSelected.png" />
                    <Setter Property="BitmapEffect">
                        <Setter.Value>
                            <OuterGlowBitmapEffect GlowColor="Black" />
                        </Setter.Value>
                    </Setter>
                </DataTrigger>

            </DataTemplate.Triggers>
        </DataTemplate>

        <!-- a custom root node for the tree -->
        <TreeViewItem x:Key="CustomRootNode">
            <TreeViewItem.Header>
                <StackPanel Orientation="Horizontal"
                    Margin="0,2,0,2">
                    <TextBlock Margin="2,0,0,0"
                     VerticalAlignment="Center"
                     FontWeight="Bold"
                     Text="Составы" />
                </StackPanel>
            </TreeViewItem.Header>
        </TreeViewItem>

        <!-- the context menu for the tree -->
        <ContextMenu x:Key="CategoryMenu">
            <MenuItem Header="Add Subcategory"
              >
            </MenuItem>

            <MenuItem Header="Remove Category"
             >
            </MenuItem>

        </ContextMenu>

        <!-- this is the style that is applied to the tree -->
        <Style x:Key="SimpleFolders"
         TargetType="{x:Type TreeViewItem}">
            <Style.Resources>
                <!-- override default brushes that show bad background colors -->
                <Brush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</Brush>
                <Brush x:Key="{x:Static SystemColors.ControlBrushKey}">Transparent</Brush>
            </Style.Resources>
            <Setter Property="HeaderTemplate"
            Value="{StaticResource CategoryTemplate}" />
            <Style.Triggers>
            </Style.Triggers>
        </Style>

        <!-- 
    A default style for treeview controls. This one will automatically
    be applied as the custom tree's 'TreeStyle' property is not set.
  -->
        <Style x:Key="SimpleTreeStyle" TargetType="{x:Type TreeView}">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0,1"
                             StartPoint="0,0">
                        <GradientStop Color="#FFF"
                        Offset="0.0" />
                        <GradientStop Color="#AAA"
                        Offset="1.0" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderThickness"
            Value="4" />
            <Setter Property="BorderBrush"
            Value="#FFA6AAAB" />
        </Style>

        <!-- sorts categories by names in ascending order -->
        <cm:SortDescriptionCollection x:Key="AscendingNames">
            <cm:SortDescription PropertyName="Header.CategoryName"
                        Direction="Ascending" />
        </cm:SortDescriptionCollection>

    </UserControl.Resources>
    <Grid>
        <!--        <local:CategoryTree x:Name="CategoryTree"
                          Items="{Binding Source={StaticResource Station}, Path=Categories}"
                          RootNode="{StaticResource CustomRootNode}"
                          NodeContextMenu="{StaticResource CategoryMenu}"
                          TreeNodeStyle="{StaticResource SimpleFolders}"
                          TreeStyle="{StaticResource SimpleTreeStyle}"
                          NodeSortDescriptions="{StaticResource AscendingNames}"
                          Margin="0,20,0,0" /> -->

        <local:CategoryTree x:Name="CategoryTree"
                          Items="{Binding Source={StaticResource Station}, Path=Categories}"
                          RootNode="{StaticResource CustomRootNode}"
                          TreeStyle="{StaticResource SimpleTreeStyle}"
                          TreeNodeStyle="{StaticResource SimpleFolders}"
                          SelectedItemChanged="CategoryTree_SelectedItemChanged"  
                          Margin="0,20,0,0" />
    </Grid>

</UserControl>
